package pojo;
import java.util.*;

public class ClassEntity {

	private static ClassEntity instance=null;
	private static Hashtable room_userlist=null;
	
	public ClassEntity(){
		room_userlist=new Hashtable();
	}
		
	public static ClassEntity getInstance()
	{
		
		if(instance==null)
			instance= new ClassEntity();
		return instance;
	}
	public void addUser(int roomid,String username)
	{
		int flag=0;
		if(room_userlist.containsKey(roomid))//加入已存在的房间
		{
			Vector<String>userlist=(Vector)room_userlist.get(roomid);
			for(int i=0;i<userlist.size();i++)
			{
				if(userlist.get(i).equals(username))
				{
					flag=1;
					break;
				}
			}
			if(flag==0)
			{
				userlist.addElement(username);
			}
			
			
		}else
		{
			System.out.println("create a new userlist");
			Vector<String> userlist=new Vector<String>();//创建新的房间
			userlist.add(username);
			room_userlist.put(roomid, userlist);
		}
		System.out.println("add new user!");
	}
	public void delUser(int roomid,String username)
	{
		Vector<String> userlist=(Vector<String>)room_userlist.get(roomid);
		int i=userlist.indexOf(username);
		userlist.remove(i);
		
	}
	public  Vector<String> getUserlist(int roomid)
	{
		Vector<String> userlist=(Vector<String>)room_userlist.get(roomid);
		return userlist;
	}
	
}
